package com.example.administrator.siku.menu.beans.adapters;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.siku.R;
import com.example.administrator.siku.menu.beans.MenuBean;
import com.example.administrator.siku.menu.beans.TypeBean1;
import com.example.administrator.siku.menu.beans.TypeBean10;
import com.example.administrator.siku.menu.beans.TypeBean2;
import com.example.administrator.siku.menu.beans.TypeBean4;
import com.example.administrator.siku.menu.beans.TypeBean5;
import com.example.administrator.siku.menu.beans.TypeBean6;
import com.example.administrator.siku.menu.beans.TypeBean6_Bean;
import com.example.administrator.siku.menu.beans.TypeBean7;
import com.example.administrator.siku.menu.beans.TypeBean8;
import com.example.administrator.siku.menu.beans.TypeBean9;
import com.example.administrator.siku.menu.beans.widget.CircleImageView;
import com.google.gson.Gson;
import com.squareup.picasso.Picasso;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by Administrator on 2016/12/6.
 */
public class RecycleViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context context;
    private List<MenuBean.FloorsBean> list;
    private Gson gson;
    private List<TypeBean6_Bean.RushRobListBean> list6;

    public RecycleViewAdapter(Context context, List<MenuBean.FloorsBean> list,Gson gson,List<TypeBean6_Bean.RushRobListBean> list6) {
        this.context = context;
        this.list = list;
        this.gson = gson;
        this.list6 = list6;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType){
            case 1:
                return new ViewHolder1(LayoutInflater.from(context).inflate(R.layout.layout_type1,parent,false));
            case 2:
                return new ViewHolder2(LayoutInflater.from(context).inflate(R.layout.layout_type2,parent,false));
            case 3:
                return new ViewHolder3(LayoutInflater.from(context).inflate(R.layout.layout_type3,parent,false));
            case 4:
                return new ViewHolder4(LayoutInflater.from(context).inflate(R.layout.layout_type4,parent,false));
            case 5:
                return new ViewHolder5(LayoutInflater.from(context).inflate(R.layout.layout_type5,parent,false));
            case 6:
                return new ViewHolder6(LayoutInflater.from(context).inflate(R.layout.layout_type6,parent,false));
            case 7:
                return new ViewHolder7(LayoutInflater.from(context).inflate(R.layout.layout_type7,parent,false));
            case 8:
                return new ViewHolder8(LayoutInflater.from(context).inflate(R.layout.layout_type8,parent,false));
            case 9:
                return new ViewHolder9(LayoutInflater.from(context).inflate(R.layout.layout_type9,parent,false));
            case 10:
                return new ViewHolder10(LayoutInflater.from(context).inflate(R.layout.layout_type10,parent,false));
            case 12:
                return new ViewHolder3(LayoutInflater.from(context).inflate(R.layout.layout_type10,parent,false));
        }
        return null;
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
        String url = list.get(position).getContent();
        if (holder instanceof  ViewHolder1){
            TypeBean1 typeBean1 = gson.fromJson(url, TypeBean1.class);
            List<TypeBean1.AccessBean> accessbeans = typeBean1.getAccess();

            ((ViewHolder1)holder).type1_tv1.setText(accessbeans.get(0).getTitle()+"");
            Picasso.with(context)
                    .load(accessbeans.get(0).getImg())
                    .into(((ViewHolder1)holder).type1_iv1);
            ((ViewHolder1)holder).type1_tv2.setText(accessbeans.get(1).getTitle()+"");
            Picasso.with(context)
                    .load(accessbeans.get(1).getImg())
                    .into(((ViewHolder1)holder).type1_iv2);
            ((ViewHolder1)holder).type1_tv3.setText(accessbeans.get(2).getTitle()+"");
            Picasso.with(context)
                    .load(accessbeans.get(2).getImg())
                    .into(((ViewHolder1)holder).type1_iv3);
            ((ViewHolder1)holder).type1_tv4.setText(accessbeans.get(3).getTitle()+"");
            Picasso.with(context)
                    .load(accessbeans.get(3).getImg())
                    .into(((ViewHolder1)holder).type1_iv4);
            ((ViewHolder1)holder).type1_tv5.setText(accessbeans.get(4).getTitle()+"");
            Picasso.with(context)
                    .load(accessbeans.get(4).getImg())
                    .into(((ViewHolder1)holder).type1_iv5);
        }
        else if (holder instanceof  ViewHolder2){
            TypeBean2 typebean2 = gson.fromJson(url,TypeBean2.class);
            List<TypeBean2.BannerBean> beans = typebean2.getBanner();
            List<View> views = new ArrayList<>();
            for (int i = 0; i <beans.size(); i++) {
                View view = LayoutInflater.from(context).inflate(R.layout.layout_type2_vp_item,null);
                ImageView type2_vp_iv = (ImageView) view.findViewById(R.id.type2_vp_iv);
                type2_vp_iv.setScaleType(ImageView.ScaleType.FIT_XY);
                TextView type2_vp_tv = (TextView) view.findViewById(R.id.type2_vp_tv);
                Picasso.with(context)
                        .load(beans.get(i).getImg())
                        .into(type2_vp_iv);
                type2_vp_tv.setText(beans.get(i).getTitle()+"");
                views.add(view);
            }
            ((ViewHolder2)holder).type2_vp.setAdapter(new RecycleViewViewePagerAdapter(views));
        }
        else if (holder instanceof  ViewHolder3){
        }

        else if (holder instanceof  ViewHolder4){
            TypeBean4 typebean4 = gson.fromJson(url,TypeBean4.class);
            Picasso.with(context)
                    .load(typebean4.getImg().get(0))
                    .into(((ViewHolder4)holder).type4_iv1);
            Picasso.with(context)
                    .load(typebean4.getImg().get(1))
                    .into(((ViewHolder4)holder).type4_iv2);
        }
        else if (holder instanceof  ViewHolder5){
            TypeBean5 typebean5 = gson.fromJson(url,TypeBean5.class);
            Picasso.with(context)
                    .load(typebean5.getImg().get(0))
                    .into(((ViewHolder5)holder).type5_iv1);
            Picasso.with(context)
                    .load(typebean5.getImg().get(1))
                    .into(((ViewHolder5)holder).type5_iv2);
        }
        else if (holder instanceof  ViewHolder6){
                if (list6.size()!=0) {
                    Log.e("onBindViewHolder: ",list6.size()+"" );
                    ((ViewHolder6) holder).type6_tv1.setText(list6.get(0).getBrandCnName() + list6.get(0).getBrandEnName() + "\n" + "¥" + list6.get(0).getSecooPrice());
                    ((ViewHolder6) holder).type6_tv2.setText(list6.get(1).getBrandCnName() + list6.get(1).getBrandEnName() + "\n" + "¥" + list6.get(1).getSecooPrice());
                    ((ViewHolder6) holder).type6_tv3.setText(list6.get(2).getBrandCnName() + list6.get(2).getBrandEnName() + "\n" + "¥" + list6.get(2).getSecooPrice());
                    ((ViewHolder6) holder).type6_tv4.setText(list6.get(3).getBrandCnName() + list6.get(3).getBrandEnName() + "\n" + "¥" + list6.get(3).getSecooPrice());
                    ((ViewHolder6) holder).type6_tv5.setText(list6.get(4).getBrandCnName() + list6.get(4).getBrandEnName() + "\n" + "¥" + list6.get(4).getSecooPrice());
                    ((ViewHolder6) holder).type6_tv6.setText(list6.get(5).getBrandCnName() + list6.get(5).getBrandEnName() + "\n" + "¥" + list6.get(5).getSecooPrice());
                    ((ViewHolder6) holder).type6_tv7.setText(list6.get(6).getBrandCnName() + list6.get(6).getBrandEnName() + "\n" + "¥" + list6.get(6).getSecooPrice());
                    ((ViewHolder6) holder).type6_tv8.setText(list6.get(7).getBrandCnName() + list6.get(7).getBrandEnName() + "\n" + "¥" + list6.get(7).getSecooPrice());

                    Picasso.with(context).load(list6.get(0).getImageUrl())
                            .into(((ViewHolder6) holder).type6_iv1);
                    Picasso.with(context).load(list6.get(1).getImageUrl())
                            .into(((ViewHolder6) holder).type6_iv2);
                    Picasso.with(context).load(list6.get(2).getImageUrl())
                            .into(((ViewHolder6) holder).type6_iv3);
                    Picasso.with(context).load(list6.get(3).getImageUrl())
                            .into(((ViewHolder6) holder).type6_iv4);
                    Picasso.with(context).load(list6.get(4).getImageUrl())
                            .into(((ViewHolder6) holder).type6_iv5);
                    Picasso.with(context).load(list6.get(5).getImageUrl())
                            .into(((ViewHolder6) holder).type6_iv6);
                    Picasso.with(context).load(list6.get(6).getImageUrl())
                            .into(((ViewHolder6) holder).type6_iv7);
                    Picasso.with(context).load(list6.get(7).getImageUrl())
                            .into(((ViewHolder6) holder).type6_iv8);
                }
                }

        else if (holder instanceof  ViewHolder7){
            TypeBean7 typeBean7 = gson.fromJson(url,TypeBean7.class);
            ((ViewHolder7)holder).title.setText(typeBean7.getTitle());
            ((ViewHolder7)holder).subtitle.setText(typeBean7.getSubTitle());
            Picasso.with(context).load(typeBean7.getImg()).into(((ViewHolder7)holder).type7_iv);
        }
        else if (holder instanceof  ViewHolder8){
            TypeBean8 typeBean8 = gson.fromJson(url,TypeBean8.class);
            Picasso.with(context).load(typeBean8.getImg()).into(((ViewHolder8)holder).type8_iv);
        }
        else if (holder instanceof  ViewHolder9){
            TypeBean9 typeBean9 = gson.fromJson(url,TypeBean9.class);
            Picasso.with(context).load(typeBean9.getBrand().get(0).getImg())
                    .into(((ViewHolder9)holder).type9_iv1);
            Picasso.with(context).load(typeBean9.getBrand().get(1).getImg())
                    .into(((ViewHolder9)holder).type9_iv2);
            Picasso.with(context).load(typeBean9.getBrand().get(2).getImg())
                    .into(((ViewHolder9)holder).type9_iv3);
            Picasso.with(context).load(typeBean9.getBrand().get(3).getImg())
                    .into(((ViewHolder9)holder).type9_iv4);
            Picasso.with(context).load(typeBean9.getBrand().get(4).getImg())
                    .into(((ViewHolder9)holder).type9_iv5);
            Picasso.with(context).load(typeBean9.getBrand().get(5).getImg())
                    .into(((ViewHolder9)holder).type9_iv6);
            Picasso.with(context).load(typeBean9.getBrand().get(6).getImg())
                    .into(((ViewHolder9)holder).type9_iv7);
            Picasso.with(context).load(typeBean9.getBrand().get(7).getImg())
                    .into(((ViewHolder9)holder).type9_iv8);

        }
        else if (holder instanceof  ViewHolder10){
            TypeBean10 typeBean10 = gson.fromJson(url,TypeBean10.class);
            ((ViewHolder10)holder).type10_name1.setText(typeBean10.getProduct().get(0).getBrandNameEN());
            ((ViewHolder10)holder).type10_name2.setText(typeBean10.getProduct().get(1).getBrandNameEN());
            ((ViewHolder10)holder).type10_name3.setText(typeBean10.getProduct().get(2).getBrandNameEN());
            ((ViewHolder10)holder).type10_name4.setText(typeBean10.getProduct().get(3).getBrandNameEN());
            ((ViewHolder10)holder).type10_name5.setText(typeBean10.getProduct().get(4).getBrandNameEN());
            ((ViewHolder10)holder).type10_name6.setText(typeBean10.getProduct().get(5).getBrandNameEN());
            ((ViewHolder10)holder).type10_name7.setText(typeBean10.getProduct().get(6).getBrandNameEN());
            ((ViewHolder10)holder).type10_name8.setText(typeBean10.getProduct().get(7).getBrandNameEN());

            ((ViewHolder10)holder).type10_price1.setText("¥"+typeBean10.getProduct().get(0).getSecooPrice());
            ((ViewHolder10)holder).type10_price2.setText("¥"+typeBean10.getProduct().get(1).getSecooPrice());
            ((ViewHolder10)holder).type10_price3.setText("¥"+typeBean10.getProduct().get(2).getSecooPrice());
            ((ViewHolder10)holder).type10_price4.setText("¥"+typeBean10.getProduct().get(3).getSecooPrice());
            ((ViewHolder10)holder).type10_price5.setText("¥"+typeBean10.getProduct().get(4).getSecooPrice());
            ((ViewHolder10)holder).type10_price6.setText("¥"+typeBean10.getProduct().get(5).getSecooPrice());
            ((ViewHolder10)holder).type10_price7.setText("¥"+typeBean10.getProduct().get(6).getSecooPrice());
            ((ViewHolder10)holder).type10_price8.setText("¥"+typeBean10.getProduct().get(7).getSecooPrice());

            Picasso.with(context).load("http://pic11.secooimg.com/product/200/200/"+typeBean10.getProduct().get(0).getPicUrl()).into(((ViewHolder10)holder).type10_iv1);
            Picasso.with(context).load("http://pic11.secooimg.com/product/200/200/"+typeBean10.getProduct().get(1).getPicUrl()).into(((ViewHolder10)holder).type10_iv2);
            Picasso.with(context).load("http://pic11.secooimg.com/product/200/200/"+typeBean10.getProduct().get(2).getPicUrl()).into(((ViewHolder10)holder).type10_iv3);
            Picasso.with(context).load("http://pic11.secooimg.com/product/200/200/"+typeBean10.getProduct().get(3).getPicUrl()).into(((ViewHolder10)holder).type10_iv4);
            Picasso.with(context).load("http://pic11.secooimg.com/product/200/200/"+typeBean10.getProduct().get(4).getPicUrl()).into(((ViewHolder10)holder).type10_iv5);
            Picasso.with(context).load("http://pic11.secooimg.com/product/200/200/"+typeBean10.getProduct().get(5).getPicUrl()).into(((ViewHolder10)holder).type10_iv6);
            Picasso.with(context).load("http://pic11.secooimg.com/product/200/200/"+typeBean10.getProduct().get(6).getPicUrl()).into(((ViewHolder10)holder).type10_iv7);
            Picasso.with(context).load("http://pic11.secooimg.com/product/200/200/"+typeBean10.getProduct().get(7).getPicUrl()).into(((ViewHolder10)holder).type10_iv8);
        }
    }

    @Override
    public int getItemCount() {
        return (list6!=null&&list!=null)?list.size():0;
       // return 5;
    }

    @Override
    public int getItemViewType(int position) {
        return (list6==null||list==null)?-1:list.get(position).getType();
    }
    //上新  海外  SALE
    public static class ViewHolder1 extends RecyclerView.ViewHolder{
        CircleImageView type1_iv1,type1_iv2,type1_iv3,type1_iv4,type1_iv5;
        TextView type1_tv1,type1_tv2,type1_tv3,type1_tv4,type1_tv5;
        public ViewHolder1(View itemView) {
            super(itemView);
            type1_iv1 = (CircleImageView) itemView.findViewById(R.id.type1_iv1);
            type1_iv2 = (CircleImageView) itemView.findViewById(R.id.type1_iv2);
            type1_iv3 = (CircleImageView) itemView.findViewById(R.id.type1_iv3);
            type1_iv4 = (CircleImageView) itemView.findViewById(R.id.type1_iv4);
            type1_iv5 = (CircleImageView) itemView.findViewById(R.id.type1_iv5);
            type1_tv1 = (TextView) itemView.findViewById(R.id.type1_tv1);
            type1_tv2 = (TextView) itemView.findViewById(R.id.type1_tv2);
            type1_tv3 = (TextView) itemView.findViewById(R.id.type1_tv3);
            type1_tv4 = (TextView) itemView.findViewById(R.id.type1_tv4);
            type1_tv5 = (TextView) itemView.findViewById(R.id.type1_tv5);
            }

    }
    //上方VP
    public static class ViewHolder2 extends RecyclerView.ViewHolder{
        ViewPager type2_vp;
        LinearLayout type2_container;
        public ViewHolder2(View itemView) {
            super(itemView);
            type2_vp = (ViewPager) itemView.findViewById(R.id.type2_vp);
            type2_container = (LinearLayout) itemView.findViewById(R.id.type2_container);
        }
    }
    //版本升级
    public static class ViewHolder3 extends RecyclerView.ViewHolder{
         public ViewHolder3(View itemView) {
            super(itemView);
           }
    }
    //大牌童装
    public static class ViewHolder4 extends RecyclerView.ViewHolder{
        ImageView type4_iv1,type4_iv2;
        public ViewHolder4(View itemView) {
            super(itemView);
            type4_iv1 = (ImageView) itemView.findViewById(R.id.type4_iv1);
            type4_iv2 = (ImageView) itemView.findViewById(R.id.type4_iv2);
        }
    }
    //欧洲包装折扣
    public static class ViewHolder5 extends RecyclerView.ViewHolder{
        ImageView type5_iv1,type5_iv2;
        public ViewHolder5(View itemView) {
            super(itemView);
            type5_iv1 = (ImageView) itemView.findViewById(R.id.type5_iv1);
            type5_iv2 = (ImageView) itemView.findViewById(R.id.type5_iv2);
        }
    }
    //茅台等商品滑动数据
    public static class ViewHolder6 extends RecyclerView.ViewHolder{
        ImageView type6_iv1,type6_iv2,type6_iv3,type6_iv4,type6_iv5,type6_iv6,type6_iv7,type6_iv8;
        TextView type6_tv1,type6_tv2,type6_tv3,type6_tv4,type6_tv5,type6_tv6,type6_tv7,type6_tv8;
        public ViewHolder6(View itemView) {
            super(itemView);
            type6_iv1 = (ImageView) itemView.findViewById(R.id.type6_iv1);
            type6_iv2 = (ImageView) itemView.findViewById(R.id.type6_iv2);
            type6_iv3 = (ImageView) itemView.findViewById(R.id.type6_iv3);
            type6_iv4 = (ImageView) itemView.findViewById(R.id.type6_iv4);
            type6_iv5 = (ImageView) itemView.findViewById(R.id.type6_iv5);
            type6_iv6 = (ImageView) itemView.findViewById(R.id.type6_iv6);
            type6_iv7 = (ImageView) itemView.findViewById(R.id.type6_iv7);
            type6_iv8 = (ImageView) itemView.findViewById(R.id.type6_iv8);
            type6_tv1 = (TextView) itemView.findViewById(R.id.type6_tv1);
            type6_tv2 = (TextView) itemView.findViewById(R.id.type6_tv2);
            type6_tv3 = (TextView) itemView.findViewById(R.id.type6_tv3);
            type6_tv4 = (TextView) itemView.findViewById(R.id.type6_tv4);
            type6_tv5 = (TextView) itemView.findViewById(R.id.type6_tv5);
            type6_tv6 = (TextView) itemView.findViewById(R.id.type6_tv6);
            type6_tv7 = (TextView) itemView.findViewById(R.id.type6_tv7);
            type6_tv8 = (TextView) itemView.findViewById(R.id.type6_tv8);

           }

    }
    //跳蚤市场的listview数据
    public static class ViewHolder7 extends RecyclerView.ViewHolder{
        ImageView type7_iv;
        TextView title,subtitle;
        public ViewHolder7(View itemView) {
            super(itemView);
            type7_iv = (ImageView) itemView.findViewById(R.id.type7_iv);
            title = (TextView) itemView.findViewById(R.id.type7_title);
            subtitle = (TextView) itemView.findViewById(R.id.type7_subtitle);
              }
    }
    //总裁包
    public static class ViewHolder8 extends RecyclerView.ViewHolder{
        ImageView type8_iv;
        public ViewHolder8(View itemView) {
            super(itemView);
            type8_iv = (ImageView) itemView.findViewById(R.id.type8_iv);
        }
    }
    //panda等品牌滑动
    public static class ViewHolder9 extends RecyclerView.ViewHolder{
        ImageView type9_iv1,type9_iv2,type9_iv3,type9_iv4,type9_iv5,type9_iv6,type9_iv7,type9_iv8;
        public ViewHolder9(View itemView) {
            super(itemView);
            type9_iv1 = (ImageView) itemView.findViewById(R.id.type9_iv1);
            type9_iv2 = (ImageView) itemView.findViewById(R.id.type9_iv2);
            type9_iv3 = (ImageView) itemView.findViewById(R.id.type9_iv3);
            type9_iv4 = (ImageView) itemView.findViewById(R.id.type9_iv4);
            type9_iv5 = (ImageView) itemView.findViewById(R.id.type9_iv5);
            type9_iv6 = (ImageView) itemView.findViewById(R.id.type9_iv6);
            type9_iv7 = (ImageView) itemView.findViewById(R.id.type9_iv7);
            type9_iv8 = (ImageView) itemView.findViewById(R.id.type9_iv8);
        }
    }
    //CARTIER等品牌滑动
    public static class ViewHolder10 extends RecyclerView.ViewHolder{
        ImageView type10_iv1,type10_iv2,type10_iv3,type10_iv4,type10_iv5,type10_iv6,type10_iv7,type10_iv8;
        TextView type10_name1,type10_name2,type10_name3,type10_name4,type10_name5,type10_name6,type10_name7,type10_name8;
        TextView type10_price1,type10_price2,type10_price3,type10_price4,type10_price5,type10_price6,type10_price7,type10_price8;

        public ViewHolder10(View itemView) {
            super(itemView);
            type10_iv1 = (ImageView) itemView.findViewById(R.id.type10_iv1);
            type10_iv2 = (ImageView) itemView.findViewById(R.id.type10_iv2);
            type10_iv3 = (ImageView) itemView.findViewById(R.id.type10_iv3);
            type10_iv4 = (ImageView) itemView.findViewById(R.id.type10_iv4);
            type10_iv5 = (ImageView) itemView.findViewById(R.id.type10_iv5);
            type10_iv6 = (ImageView) itemView.findViewById(R.id.type10_iv6);
            type10_iv7 = (ImageView) itemView.findViewById(R.id.type10_iv7);
            type10_iv8 = (ImageView) itemView.findViewById(R.id.type10_iv8);

            type10_name1 = (TextView) itemView.findViewById(R.id.type10_name1);
            type10_name2 = (TextView) itemView.findViewById(R.id.type10_name2);
            type10_name3 = (TextView) itemView.findViewById(R.id.type10_name3);
            type10_name4 = (TextView) itemView.findViewById(R.id.type10_name4);
            type10_name5 = (TextView) itemView.findViewById(R.id.type10_name5);
            type10_name6 = (TextView) itemView.findViewById(R.id.type10_name6);
            type10_name7 = (TextView) itemView.findViewById(R.id.type10_name7);
            type10_name8 = (TextView) itemView.findViewById(R.id.type10_name8);

            type10_price1 = (TextView) itemView.findViewById(R.id.type10_price1);
            type10_price2 = (TextView) itemView.findViewById(R.id.type10_price2);
            type10_price3 = (TextView) itemView.findViewById(R.id.type10_price3);
            type10_price4 = (TextView) itemView.findViewById(R.id.type10_price4);
            type10_price5 = (TextView) itemView.findViewById(R.id.type10_price5);
            type10_price6 = (TextView) itemView.findViewById(R.id.type10_price6);
            type10_price7 = (TextView) itemView.findViewById(R.id.type10_price7);
            type10_price8 = (TextView) itemView.findViewById(R.id.type10_price8);
        }
    }
    //新客专享  男士专区等
//    public static class ViewHolder12 extends RecyclerView.ViewHolder{
//        ViewPager type1_vp;
//        LinearLayout type1_container;
//        public ViewHolder12(View itemView) {
//            super(itemView);
//            type1_vp = (ViewPager) itemView.findViewById(R.id.type1_vp);
//            type1_container = (LinearLayout) itemView.findViewById(R.id.type1_container);
//        }
//    }
}
